<?php
namespace Common\Models;
use Common\BaseModel;
class InvitecodeShares extends BaseModel
{
	public $res;
	public $expire;
    public function initialize()
    {
        parent::initialize();
        $this->setSource('f_invitecode_shares');
    }

	public function find_list(){
	    $lists = $this::find(
	        array(

            )
        )->toarray();
	    return $lists;
    }


	public function inviteShare($user_info){
        $listObj = $this::find('published=1');
        $list=$listObj->toArray();
        $exclusive_code = $user_info['exclusive_code']?$user_info['exclusive_code']:$user_info['invite_code'];
        
        $FAppConfigDb = new AppConfig();
        $app_config_list = $FAppConfigDb->find_list("base_config");
        foreach ($list as $k=>$val){
            $list[$k]['url'] = $app_config_list['android_app_download_url'].'?invite_code='.$exclusive_code;
            $list[$k]['invite_code'] =$exclusive_code;
            $list[$k]['word'] = str_replace("code",$user_info['invite_code'],$val['word']);
            $list[$k]['posterBase64'] = '';
            $list[$k]['posterPath'] = '';
        }
       return $list;
    }


    public function inviteShare_v2($user_info){
        $listObj = $this::find('published=1');
        $list = $listObj->toArray();
        $new_list = array();
        foreach ($list as $k=>$val){
            $val['url'] = $val['url'].'?invite_code='.$user_info['invite_code'];
            $val['invite_code'] = empty($user_info['exclusive_code']) ? $user_info['invite_code'] : $user_info['exclusive_code'];
            $val['word'] = str_replace("code",$user_info['invite_code'],$val['word']);
            $new_list[$val['classify']]['classify'] = $val['classify'];
            $new_list[$val['classify']]['list'][] = $val;
        }

        $res = array();
        foreach ($new_list as $key => $val){
            $res[] = $val;
        }

        return $res;
    }
}
